package com.vector.tool;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class controller {
    @ResponseBody
    @RequestMapping("/tool1")
    public String tool1(String ip1, String ip2, String ip3, String ip4, String ip9, Model model) {
        int IP1 = Integer.valueOf(ip1);
        int IP2 = Integer.valueOf(ip2);
        int IP3 = Integer.valueOf(ip3);
        int IP4 = Integer.valueOf(ip4);
        int IP9 = Integer.valueOf(ip9);
        subnetMaskCaculate sub = new subnetMaskCaculate();
        List<Integer> list = sub.Two(IP9);
        String str = null;
        if (IP1 >= 1 && IP2 >= 0 && IP3 >= 0 && IP4 >= 0 && IP1 <= 223 && IP2 <= 255 && IP3 <= 255 && IP4 <= 255 && IP9 >= 1 && IP9 <= 32) {
            if (IP1 <= 127) {

                Aip aip = new Aip(IP1, IP2, IP3, IP4, list.get(0), list.get(1), list.get(2), list.get(3));
                str = "地址合法,为A类地址" +
                        "\n" + "\n" + aip.ShowA();
            } else if (IP1 <= 191) {
                Bip aip = new Bip(IP1, IP2, IP3, IP4, list.get(0), list.get(1), list.get(2), list.get(3));
                str = "地址合法,为B类地址" +
                        "\n" + "\n" + aip.ShowB();
            } else if (IP1 <= 223) {
                Cip aip = new Cip(IP1, IP2, IP3, IP4, list.get(0), list.get(1), list.get(2), list.get(3));
                str = "地址合法,为C类地址" +
                        "\n" + "\n" + aip.ShowC();
            }
        } else {
            str = "地址不合法,请重新输入";
        }

        return str;
    }
}
